Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
"Página no encontrada/controlador 404" a Swift Express Server

Estoy escribiendo el servidor más simple a través de Swift Express

Y quiero agregar un controlador personalizado para "url no encontrada" para que si el usuario escribe "/ notFoundUrl" verá algo como eso: "Url "notFoundUrl" no encontrada, vaya a la página de inicio".

He añadido:

 app.get("/:notFoundUrl+") { (request:Request<AnyContent>)->Action<AnyContent> in print(request.params["notFoundUrl"]) return Action<AnyContent>.render("index", context: ["hello": "Page Not Found: " + request.params["notFoundUrl"]!]) }

Pero no es apropiado porque:

  • El orden sí importa.
  • No puedo devolver el error 404.

Entonces, ¿cómo agregar "Página no encontrada/controlador 404" personalizado a Swift Express Server ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Es mucho más simple de lo que estás tratando de hacerlo.

 /// Custom page not found error handler app.errorHandler.register { (e:ExpressError) in switch e { case .PageNotFound(let path): return Action<AnyContent>.render("404", context: ["path": path], status: .NotFound) default: return nil } }

El do completo se puede encontrar aquí: https://github.com/crossroadlabs/Express/blob/master/doc/gettingstarted/errorhandling.md

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!